<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui">
<ui:composition template="/template/master.xhtml">

	<ui:define name="tituloTamplate">Ingrediente | Pizzaria</ui:define>

	<ui:define name="conteudo">
		<p:layoutUnit position="center">

			<h:form id="form" prependId="false">
				<p:dataTable id="tabela" var="ingrediente"
					value="#{ingredienteBean.listaIngrediente}" paginator="true"
					rows="10" rowsPerPageTemplate="5,10,15"
					emptyMessage="Nenhum registro cadastrado">

					<f:facet name="header">
						<p:commandButton value="Cadastrar" style="float: left;"
							id="modalDialogButton" onclick="PF('dialogCadastrar').show();"
							type="button"></p:commandButton>
						<p:outputLabel value="Lista dos Ingredientes" />
					</f:facet>

					<p:column headerText="Nome" sortBy="#{ingrediente.nome}">
						<h:outputText value="#{ingrediente.nome}" />
					</p:column>

					<p:column headerText="Preço" sortBy="#{ingrediente.preco}">
						<h:outputText value="#{ingrediente.preco}" />
					</p:column>

					<p:column headerText="Opções"
						style="width:10%; text-align: center;">
						<p:commandLink title="Alterar"
							oncomplete="PF('dialogAlterar').show();"
							update=":formAlterar:panelAlterar">
							<h:graphicImage library="images" name="editar.png"></h:graphicImage>
							<f:setPropertyActionListener
								target="#{ingredienteBean.ingrediente}" value="#{ingrediente}" />
						</p:commandLink>

						<p:commandLink title="Excluir" action="#{ingredienteBean.excluir}"
							update="tabela">
							<h:graphicImage library="images" name="delete.png" />
							<p:confirm header="Exclusão" message="Deseja realmente excluir?"
								icon="ui-icon-alert" />
							<f:setPropertyActionListener
								target="#{ingredienteBean.ingrediente}" value="#{ingrediente}" />
						</p:commandLink>

						<p:confirmDialog global="true" severity="alert">
							<p:commandButton value="Yes" type="button"
								styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
							<p:commandButton value="No" type="button"
								styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
						</p:confirmDialog>

					</p:column>
				</p:dataTable>
			</h:form>

			<h:form>
				<p:dialog header="Cadastrar Ingrediente" widgetVar="dialogCadastrar"
					resizable="false">
					<p:panel id="panelCadastrar">
						<h:panelGrid columns="3">
							<h:outputLabel value="Nome: " />
							<p:inputText id="nome"
								value="#{ingredienteBean.ingrediente.nome}" required="true"
								requiredMessage="Campo Obrigatório" />
							<p:message for="nome" display="default" />

							<h:outputLabel value="Preço: " />
							<p:inputText id="preco"
								value="#{ingredienteBean.ingrediente.preco}" required="true"
								requiredMessage="Campo Obrigatório" />
							<p:message for="preco" display="default" />

							<f:facet name="footer">
								<center>
									<p:commandButton type="reset" value="Limpar" />
									<p:commandButton value="Salvar"
										actionListener="#{ingredienteBean.gravar}"
										update=":form:tabela panelCadastrar"
										oncomplete="if (args &amp;&amp; !args.validationFailed) PF('dialogCadastrar').hide();" />
								</center>
							</f:facet>
						</h:panelGrid>
					</p:panel>
				</p:dialog>
			</h:form>

			<h:form id="formAlterar">
				<p:dialog id="te" header="Alterar Ingrediente"
					widgetVar="dialogAlterar" resizable="false">
					<p:panel id="panelAlterar">
						<h:panelGrid columns="3">
							<h:outputLabel value="Nome: " />
							<p:inputText id="nome"
								value="#{ingredienteBean.ingrediente.nome}" required="true"
								requiredMessage="Campo Obrigatório" />
							<p:message for="nome" display="default" />

							<h:outputLabel value="Preço: " />
							<p:inputText id="preco"
								value="#{ingredienteBean.ingrediente.preco}" required="true"
								requiredMessage="Campo Obrigatório" />
							<p:message for="preco" display="default" />

							<f:facet name="footer">
								<center>
									<p:commandButton value="Salvar"
										actionListener="#{ingredienteBean.alterar}"
										update=":form:tabela panelAlterar"
										oncomplete="if (args &amp;&amp; !args.validationFailed) PF('dialogAlterar').hide();" />
								</center>
							</f:facet>
						</h:panelGrid>
					</p:panel>
				</p:dialog>
			</h:form>
		</p:layoutUnit>
	</ui:define>

</ui:composition>
</html>